<?php

use think\migration\Migrator;
use think\migration\db\Column;

class SysDb extends Migrator {

    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change() {
        // create the table 新增用户表
        $table = $this->table('users', array('engine' => 'MyISAM'));
        $table->addColumn('username', 'string', array('limit' => 15, 'default' => '', 'comment' => '用户名，登陆使用'))
                ->addColumn('password', 'string', array('limit' => 32, 'default' => md5('123456'), 'comment' => '用户密码'))
                ->addColumn('login_status', 'boolean', array('limit' => 1, 'default' => 0, 'comment' => '登陆状态'))
                ->addColumn('login_code', 'string', array('limit' => 32, 'default' => 0, 'comment' => '排他性登陆标识'))
                ->addColumn('last_login_ip', 'integer', array('limit' => 11, 'default' => 0, 'comment' => '最后登录IP'))
                ->addColumn('last_login_time', 'datetime', array('default' => 0, 'comment' => '最后登录时间'))
                ->addColumn('is_delete', 'boolean', array('limit' => 1, 'default' => 0, 'comment' => '删除状态，1已删除'))
                ->addIndex(array('username'), array('unique' => true))
                ->create();
        // create the table 新增管理员表
        $table = $this->table('admin', array('engine' => 'MyISAM'));
        $table->addColumn('admin_name', 'string', array('limit' => 15, 'default' => '', 'comment' => '管理员名，登陆使用'))
                ->addColumn('password', 'string', array('limit' => 32, 'default' => md5('123456'), 'comment' => '管理员密码'))
                ->create();
        
        // create the table 新增库位表
        $table = $this->table('storage', array('engine' => 'MyISAM'));
        $table->addColumn('storage_name', 'string', array('limit' => 15, 'default' => '', 'comment' => '库位名'))
                ->addColumn('desc', 'string', array('limit' => 32, 'default' => "", 'comment' => '描述'))
                ->create();
    
    }

}
